// align.C -- Written on Jun 1st, 2024 by SUN Yazhou
// Trigger alignment among all the DAQs
void align(){
  TFile *f = new TFile(getenv("TMP1"));
  TTree *etf = (TTree *)f->Get("etf");
  TCanvas *c = new TCanvas("c", "Trigger alignment among all the DAQs", 1600, 800);
  c->Divide(2, 1);
  c->cd(1);
  etf->Draw("-tstart4[0].dt():tstart2[0].dt()>>h1(500, -5., 10., 500, -5., 10.)", "", "colz");
  TH1F *h1 = (TH1F *)f->Get("h1");
  h1->GetXaxis()->SetTitle("Tstart: TL-TR [ns] DAQed by ETF-PXI");
  h1->GetYaxis()->SetTitle("Tstart: -(TL-TR) [ns] DAQed by F1-PXI");
  h1->GetYaxis()->SetTitleOffset(1.2);
  h1->SetTitle("DAQ Alignment => F1 PXI v.s. ETF PXI");

  c->cd(2);
  etf->Draw("tstop.time()-tstart2.time():tstop0_v.time()-tstart2_v.time()"
    ">>h2(500, 110., 200., 500, 110, 200)", "", "colz");
  TH1F *h2 = (TH1F *)f->Get("h2");
  h2->GetXaxis()->SetTitle("tof1: T0->T1 [ns]: DAQed by ETF VME");
  h2->GetYaxis()->SetTitle("tof1: T0->T1 [ns]: DAQed by ETF PXI");
  h2->GetYaxis()->SetTitleOffset(1.2);
  h2->SetTitle("DAQ Alignment => ETF PXI v.s. ETFVME");

  c->Print("align.pdf");
} // end vis
